package com.example.mq.mqserver.core;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/*
    表示一个消息队列
 */
@Data
public class MSGQueue {
    //队列的身份标识
    private String name;
    //表示是否持久化保存，true是，false不是
    private boolean durable = false;
    //表示是否是私用
    private boolean exclusive = false;
    //表示当队列无人使用时是否删除
    private boolean autodelete = false;
    //表示创建队列时是否指定一些额外参数
    private Map<String, Objects> arguements = new HashMap<>();

    public String getArguements() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(arguements);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    public void setArguements(String arguementsjson) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            this.arguements = objectMapper.readValue(arguementsjson, new TypeReference<HashMap<String, Objects>>() {
            });
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

}
